import * as THREE from 'three'
import {
    OrbitControls
} from 'three/examples/jsm/controls/OrbitControls.js'
// console.log(THREE)

var dir = false
// 场景
const scene = new THREE.Scene();
// 相机 （透视相机）  角度、宽高比、近端面、远端面
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.set(0, 0, 5);
scene.add(camera);

// 几何体与材质
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshBasicMaterial({
    color: 0x00ff00
});
const cube = new THREE.Mesh(geometry, material);
// 设置位置
cube.position.set(0, 0, 0)
// 缩放
cube.scale.set(3, 2, 1)
// 旋转
// cube.rotation.set(Math.PI / 4, 0, 0)
scene.add(cube);

// 渲染
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

// 坐标轴辅助器
const axesHelper = new THREE.AxesHelper(5);
scene.add(axesHelper);
// 使用渲染器   通过相机将场景渲染
// renderer.render( scene, camera );

//新增时钟
const clock = new THREE.Clock()

// 新增轨迹控制器
const controls = new OrbitControls(camera, renderer.domElement);

function render(time) {
    // cube.rotation.x += 0.01
    // if (!dir) {
    //     cube.position.x += 0.01
    //     cube.position.y += 0.01
    //     cube.position.z += 0.01
    //     if (cube.position.x > 5) {
    //         dir = true
    //         cube.scale.set(1, 2, 3)
    //     }
    // } else {
    //     cube.position.x -= 0.01
    //     cube.position.y -= 0.01
    //     cube.position.z -= 0.01
    //     if (cube.position.x < 0) {
    //         dir = false
    //         cube.scale.set(3, 2, 1)
    //     }
    // }
    // console.log("运行总时长 = ", clock.getElapsedTime(), " 两次时间间隔 = ", clock.getDelta())
    renderer.render(scene, camera);
    requestAnimationFrame(render);
}

render();